
import { GlobalVar } from "../../common/globalvar";
import lgxcom from '../../common/common'
import {LGXEnums}  from "../../common/sysenum";

import fillinfo from "../../common/struct/fillinfo";

class ConfigSvc {
    constructor(dataManger) {
        this.dataManger = dataManger;
    }

    config(type, val, canvasID) {
        console.log("ConfigSvc sys option type:" + type + "  val:" + val);
        let mapInfo = this.dataManger.getMapViewInfo();
        if (type == "disLineWidth") {
            mapInfo.setLineWidthShow(val);
        }
        else if (type == "grid") {
            let flag = parseInt(val.dis);
            if (flag == 1) {
                mapInfo.setDisGrid(true);
            }
            else {
                mapInfo.setDisGrid(false);
            }
            mapInfo.setGridColor(val.color);
            mapInfo.setGridSpan(parseInt(val.span));
        }
        else if (type == "backcolor") {
            //"rgba(128, 128, 128, 1)";
            let strLen = val.length;
            let rgbStr = val.substr(5, strLen - 6);
            let strList = rgbStr.split(",");
            if (strList.length == 4) {
                let red = parseInt(strList[0]);
                let green = parseInt(strList[1]);
                let blue = parseInt(strList[2]);
                let alpha = parseInt((parseFloat(strList[3]) * 255));
                let colorIntVal = alpha;
                colorIntVal = (colorIntVal << 24) | (blue << 16) | (green << 8) | red;
                GlobalVar.backcolor = new lgxcom.LGXColor();
                GlobalVar.backcolor.setColorByValue(colorIntVal);
                mapInfo.setBackColor(GlobalVar.backcolor);
            }

            let canvasArea = document.getElementById(canvasID);
            canvasArea.style.backgroundColor = val;
            canvasArea.style.border = "3px solid rgb(90, 88, 88);";
        }
        else if (type == 'editMode') {
            this.switchWorkMode(val);
        }
        else if (type == 'runningMode') {
            this.switchRunningMode(val);
        }
    }

    switchWorkMode(mode) {
        GlobalVar.editMode = mode;
        switch (mode) {
            case "autocad":
                GlobalVar.easySelMode = false;
                GlobalVar.lineVisionType = LGXEnums.lineVisionType.straight;
                GlobalVar.disLineWidth = false;//显示线宽
                GlobalVar.defaultLineWidth = 0;
                GlobalVar.fillInfo.fillStyle = LGXEnums.LGXFillStyle.pattern;
                GlobalVar.lineInfo.color.setVal(255,255,255,255);
                break;

            case "viso":
                GlobalVar.easySelMode = true;
                GlobalVar.lineVisionType = LGXEnums.lineVisionType.cross;
                GlobalVar.disLineWidth = true;//显示线宽
                GlobalVar.fillInfo.fillStyle = LGXEnums.LGXFillStyle.SOLID;
                GlobalVar.defaultLineWidth = 2;
                GlobalVar.lineInfo.color.setVal(91,155,213,255);
                GlobalVar.fontInfo.fontColor.setVal(0,0,0);
                
                break;

            case "xmind":
                GlobalVar.easySelMode = true;
                GlobalVar.lineVisionType = LGXEnums.lineVisionType.curve;
                GlobalVar.disLineWidth = true;//显示线宽
                GlobalVar.fillInfo.fillStyle = LGXEnums.LGXFillStyle.SOLID;
                GlobalVar.defaultLineWidth = 2;
                GlobalVar.lineInfo.color.setVal(91,155,213,255);
                break;
        }
    }

    switchRunningMode(mode) {
        GlobalVar.runningMode = mode;
    }

}

export default { ConfigSvc }